package com.example.offer.no0006.impl;

import java.util.Stack;

import com.example.offer.no0006.ListNode;
import com.example.offer.no0006.Solution;

/**
 * @author yumuhui <yumuhui@kuaishou.com>
 * Created on 2021-05-13
 */
public class StackSolutionImpl implements Solution {

    @Override
    public int[] reversePrint(ListNode node) {

        Stack<ListNode> stack = new Stack<>();
        ListNode temp = node;
        while (temp != null) {
            stack.push(temp);
            temp = temp.next;
        }
        int size = stack.size();
        int[] print = new int[size];
        for (int i = 0; i < size; i++) {
            print[i] = stack.pop().val;
        }
        return print;
    }
}
